<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2025/6/25
  Time: 13:53
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-2.0.0.min.js"></script>
<html>
<head>
    <title>Title</title>
</head>
<body>
<table border="1px">
    <tr id="snack-head">
        <th>id</th>
        <th>名称</th>
        <th>库存</th>
        <th>价格</th>
        <th>操作</th>
    </tr>
</table>
</body>
<script>
    SnackQueryAll();
    function SnackQueryAll() {
        $.ajax( {
            "url"          :  "SnackQueryAllServlet",
            "type"         :  "get",
            "data"         :  "data",
            "dataType" :  "text",
            "beforeSend": function() {
            },
            "success":  function(result) {
                var snackList=JSON.parse(result);
                var temp="";
                for (var s in snackList){
                    temp+=`
                         <tr>
                            <td>\${snackList[s].snackid}</td>
                            <td>\${snackList[s].snackname}</td>
                            <td>\${snackList[s].stock}</td>
                            <td>\${snackList[s].price}</td>
                            <td><a href="SnackQueryById.jsp?snackid=\${snackList[s].snackid}">购买</a></td>
                        </tr>
                    `
                }
                $("#snack-head").siblings().remove();
                $("#snack-head").after(temp);
            },
            "error":  function() {
            }
        } );
    }
</script>
</html>
